Fixed multiple issues causing dangling references to discarded queries