Working version. Would need to be modified for varying number of peaks fitted.