Added undo functionality in a stack