Changed an algorithm of valley detection to follow valley