Clean up some code around refresh of Query