Inserted left out "var" statements, removed unused local value, inserted...

... missing semicolon, removed duplicate statement.