Case results query perf

lots of perf fixes