Changed the code to use the max function.