Clean up metadata parsing and query parsing