broke up the huge sql statement into smaller bits