Don't you need to check FLAGS_out_metadata here as well?  That seems to be required in the function, and I don't see it being checked...