refactoring and junit tests