minor refactoring + unit tests