Fixed some bugs with the undo feature