Improved minimising function

Or rather, tailored one for the problem at hand... #winning