A few cleanups to fix the query stuff