put var i into a single declaration at top of function