Wrote initial optimization code.