Add undo for drawing mask.
Refactoring.