Partial Code Cleanup and major efficiency improvements