Refactoring

- replaced .caret() calls with getCaretPos/setCaretPos where possible
- replaced all .val() calls with getValue/setValue
- refactored smart caret positioning code
Refactor

- remove old commented code
- use *constants* for all keycodes
- remove unused variables
- remove/rewrite try/catch blocks