Add support for saving metadata on queries.

Also since python is passing by object, I make a clean copy of metadata in the new version before modifying it.