What I do sometimes when something just isn't working as I want it to, is to take my knowledge of how it is supposed to work and then write the code again from scratch.
Break the effect down in small parts, plan what variables, arrays, etc is needed for each part, put those into code, document it, and then start putting the code together one function at a time, one line at a time. It will often also make the code more clear and easy to deal with.
Not sure if you want to spend time on doing so, but it has helped me previously doing so and it might help you.
Also always try and make code reusable, which it why its important to break things down in smaller parts. That way you only have to write code that does various things once, and can reuse it later for something else. Keep functions self contained so that they only need input from outside via parameters and does not depend too much on global variables, arrays and such.
Just a couple of tips that I though of that might assist you in getting on with the effect. As far as the actual code you already have, I don't really have much that I can help with. Its a long while since I dropped FB, and I haven't really kept up with the syntax and such.
But it does sound like you still have some problems with your interpolation math.