fixed a bug where the internal query counter wasn't correctly decreased