refactored code, simplified keyboard handling, js-lint-ed

I've tried to reduce code complexity a little bit by removing the need to use on and off for the keyhandler. Instead I added a state handler. Also jslint-ed the code.