small refactor and tests