code cleanup for figure2dot
move more functionality to cleanfigure()