Fix using close when query is FALSE