fixed failing tests, some refactorings