refactoring existing code for milestone 2