query improvements and tests
Merge branch 'master' of https://github.com/martflu/amanaman