Optimize database queries
Merge pull request #42 from mzemel/optimize_queries

Optimize database queries