Some fixes to queries