Some refactoring and monkey patching to get Domains working properly