Fixing some errors in Query