Refactored detectPeaks. Error is now always calculated as the difference between peak and estimated peak.