Optimizer optimizations and bug fixed and working

Total testing iterations of final code: 65,000
Test code can be found a few commits back if more testing is needed.