fix order of emitting metadata