Refactor the caret implementation