Yikes, that's way too much code to sift through. Get your problem boiled down to an SSCCE, and we'll go from there.