peak calculations moved into a function, for parallelisation
peak calcs in a function, for parallelisation