small refactor, fix tests