Detect ctrl-z for undo
Some minor changes