Fixed out of bounds read.
fix backspace bug, simplify a bit