Further work on adding prefixes to content.

Also fixes to references, now their mapping/usage information will be
correct each time an image is generated.