More mem leak fixes from queries