completed get_max function