working code on small graph