Modified to use the method shown in the example assignment.