did some refactoring to assignment 9