Fixed bug when backspacing UTF8 characters in the command box. Also some code cleanup