working find-max function