Simplified the optimize function (+ changed to 2.10 due to some dependency hell)