Improved undo function. Added redo function.