added some code to generate graph