Updated to code to apply to new RunQuery functionality