Perhaps all of the realm checking/setting should be done in modules/generate_assertion.js instead of here.