fix query improvements (complements be3c0b6e04d93d21783fcde20ce0ce3c5eaf1e45)