Code optimizations. 

Made sections of code faster using cprofile readings.