Added memoize to min and max