Optimize various queries
Merge branch 'dev' of https://github.com/nZEDb/nZEDb into dev