refactoring for assignment 3