fixed test, minor refactoring
refactorings, added tests