That is WAY too much code for anybody to wade through. We have hundreds of posts here- we simply do not have time to do your debugging for you. Boil your problem down to an SSCCE (the first 'S'...