refactoring and implementing more tests