Whoa, there's a loop that could use some breaking up!  Is there anything you can factor out of it to make it readable?