Implemented peak-and-valley-detection, with bells and whistles