Factored out existing optimisers to use new interface.