Clean up code a bit and improve handling of multiple metadata files.