test&refactor - added more units tests, refactored code