code tidy up. improved query speed but still too slow for report for sponsors