[fix] move var decleration to beginning of function