Refactoring caret.js a little more