Added graph cleaning function