Misha's fixes
method works fine and finds minimum