Ahh, right, I saw that it was originally generated by Builder and didn't realise that you had customised it.
Someone would have to be very generous with their time to go through the code and also be able to understand what you are trying to achieve to see what is going wrong.
You are likely going to need to break this down a lot more to very specific detail to get help, and just deal with one issue at a time. Start with the problem that generates the error, as that will be easiest to fix. describe exactly what you are intending, what wordPos is, where it comes from, how it used, etc. Also, please copy and paste complete error messages instead of partial , blurred screenshots.