Minor bug in writing metadata