some more bloody refactoring