corrected peaks function