Clean up metadata handling

Swap out a bunch of ugly nested cases for pattern matching
under Maybe