Fix some queries returning wrong number of rows.
Merge pull request #9 from markmont/master

Fix some queries returning wrong number of rows.