small refactor and fixes