General linting and code cleanup

JSHint turned up a few bugs, as well as various unused variables, etc.
(Most of these were my fault to begin with...)