Move derefering logic into a plugin and add configuration.