refactoring, cleaning, adding missing unit tests