Adding next highest/lowest algorithm