Major rewrite of query functions

- Changed internal creation of query objects
- Added new public method "count"
- Added unit tests
Edit to match db.py changes, cleanup
Fixed requires_auth error, PEP8
Overview panel displays two tables