added tests;refactoring