max function fixed