Fixed incorrect min/max function.