[FIX] fixes suggested by Chris

- correctly handle update of shared variable
- move PeakType out of loops