Refactor the code based on code review and discussion in class.