I always find that whenever I think I’ve found a buh, the engine is basically doing exactly what I’m asking it to do.
So, somehow, you’re asking it to perform this behaviour, and not seeing it.
A good piece of advice is always to strip things to almost nothing, then build up again.
I’m not seeing anything in particular when I look at your code, but there is a mistake somewhere in there. Stripping it right down will help you find it.
Sorry not to be more helpful…