Correct \n inserton
Fix a backspace problem
Add buffer invariant, seems to work