I'm not too fond of variable names like `$tmp` as they provide no information about what the variable actually represents. Combined with a lack of comments understanding what is going only only becomes more difficult.

I know that the original code is not any better in this regard but we can only try to make it better going forward.