corrected detectSpikes()