beginnings of peak-detection alogrithm