Implemented undo support. Closes #324.