btw, I don't exactly like having all `var` at the start of the function as rwaldron does ;)

I think this is a matter of style and that's why I nearly never remark that, but don't do it just if you think it's the right thing to do. It's not, it's just a matter of style, so do what you think is best here.

Only thing that is (imho) not right is to "var" twice the same variable.