Fix query_factory iterator bug, add Countable

- query_factory rewind() logic was incorrect
- added Countable implementation