changed some variable declarations to use var