added function from Joke to search local maxima