Added undo function and other improvements