Refactor peaks.js