fixing minor errors e.g. redefined variable

Some errors found via JSHint.