Optimized imports and tidied up dependecy tree.

Using newer math3 code for apache optimiser.  Apparently, there is functionality for non-linear solvers now, so it might be worth trying to implement these in the future.