Refactorig the detection of minima