Clean up queries before closing connections

Not required, but neat.