The backend references now use a common closing function so that all variables are reset to proper states. The stored queries weren't always freed and they would leak memory if left open.