Fixed to calculate minimum properly.