possibly fix extrema detection