State mode + ESC sequences + bug fix