modified findExtrema