made corrections

- deleted document.onkeydown (add document.addEventListener);
- made main function IIFE (not problem with global scope);