Optimize find-min function.