Try to build smaller methods out of what is inside this for to try to reduce the cyclomatic complexity of this.