fixing minor errors e.g. redefined variable

Some errors found via JSHint.
For some reason I can't find where this was defined before.