Reduce number of SQL queries on some pages

Resolves gh-16