Refactoring and Adding Tests