Continue metadata layer implementation.

Note: Code doesn't compile. It's in the middle
of being heavily modified.