Pre Jim's SQL rework