fixed tests and some refactoring