Fix bug in _query and count