finished max-min function, part 2