improve peak detection algorithm