Fixes up queries