Move var declaration before usage

to resolve the free variable compilation warning.