move var declaration outside of loop