and some more general refactoring