refactoring and creating unit tests