Optimization branches merge.

Merging in the work done on optimization.