Refactor logic out of caret.handle()