This method is now huge, unreadable, with a lot of side effects.  This also makes in very hard to write a unit test for.

Try to limit methods to 20 lines, not counting whitespace and comments..