Fix bug #1008 with modal visualization and small refactoring.