Fixing error on query