Yes, I think this is still incompletely refactored. I was on my way to see how far I can vectorize it but then payed more attention to get it actually working. E.g. you can see that the sy / cy are already computed outside this loop. So there should be no reason to keep this here as the result will always be the same. Let's do this and see what's the next opportunity for improving efficiency.