graph generation code cleanup