I have a Wordpress 4.0.2 site. I engaged a programmer to do some customization to it. He wrote all the php code into the functions.php of my theme. I didn't realize that this was a bad move as I was new to Wordpress customization & I relied upon him for his 'expert' advice.

While the codes are all working fine the side effect of his work is as follows:

1. The site is sluggish
2. It throws up some hidden javascript errors that prevents other Wordpress plugins from functioning
3. WordPress' admin-ajax.php has been blocked from loading
4. It is loading jquery multiple times from an external google api link
5. I can't update / change my theme anymore for fear that the functions.php file will no longer work on the new theme
6. The searchability is unstable
7. I dare not upgrade my version of Worpress for fear that something might get messed up

Additional Info
One of the core functions of this Wordpress site is to query an external Mysql database containing approximately 20 million records. Could this be a contributory factor to the sluggishness of the site?

Under such circumstances, what is the best way to maintain all the customization but improve the performance of this site?

Thanks for your advice.