Move var declarations to function start

Just moved the var declarations to the top of the function as the JS interpreter hoists them to the top on the first pass in any case. More idiomatic. Love this code!