Added undo feature.

Minor fixes as well.