Fixed extrema detection and envelope creation
Added max iteration parameter