added the undo functionality (main method not yet implemented)