Optimize out most of my for loops