Debuggin can be a pain. Try to isolate the bad guy one by one. I am rather sure it's a typo somewhere. Unlogical Errors are caused by typos most times. Please understand, not a lot of people like to go trough long codes of other people to find a bug.
Edit: May also be it's a global/local thing.
Edit: May also be it's a global/local thing.