Fix 165 two phase queries

Just some rough ideas at this point. Feedback welcome. Will flesh out more tomorrow.