refactoring, added junit tests