Resolve 2 query problem cases and various smaller improvements