Refactoring and started adding tests