Optimized a number of functions. Still need testing and to optimize as per notes in file