Did something get accidentally copy-pasted here?  This is a huge block of new code, and it looks like it's in the middle of the old code.