Fix bug in metadata writing. Allow metadata at top.
Merge pull request #12 from ranbo/metadata2

Fix bug in metadata writing. Allow metadata at top.