improving optimisation routine