tweaks and query optimizations