added 7 unit tests, refactoring fixes