Improved undo feature to use command