refactored the metadata module.

Pulled it out of the layers app and into the base app. It will now be used by
both the layers and the documents app.