Refactor metadata parsing significantly. Fixes #195.