combine min and max function