method works fine and finds minimum