WIP: Beginning work on modularizing components.

Moving optimization code into a seperate module.
TODO: Think about optimization interface.