move query code that sprinkles functionality