some more refactoring + testing