implemented tests, refactoring