some optimizations to inner functions of find_peaks