Hi John,
As implied by Shreepad, please provide a simplified version of your code. I suspect there are more issues than the (useful) one Shree mentioned.
Then folks can help address the errors, and you can then re-factor all of your code.
Cheers,
Jody