Optimization

Gigantic optimization update. I will work on some comments later. I have
run out of time lol. If you have any comments or confusions I will get
to them as soon as I can on Google groups.