I'll just say it once here, lest I end up saying it many, many times through this file: there should be better spacing throughout the entire file (in terms of empty lines).  Much of this is just walls of code—very difficult to read.