Some simplfications.
Caret moving fixed and tests added.