tidy up of api query implementations and small optimizations
Merge branch '2.0-maint' into 2.1-maint