some fancy refactoring