Updated code per assignment.