Speed improvements of queries
Merge pull request #781 from annando/master

Speed improvements of queries