Working on refactoring and tests