This code bugs me.
It isn’t wrong, and it is going to produce the right result. But is ain’t pro code, in the sense that this code lacks an important *ities.
Just to cut down on the guessing, I marked the exact part that bugs me. Can you see the issue?