insert mode refactoring. cleanups and tests needed