issue #4

refactoring and tests