more tests, fixing tests and refactoring