Implemented undo functionality