first peak detection stuff