Add UT coverage, small refactoring