fixed small bug, minimization seems to work, and it's fast