properly rewrite all refs when loading schema