added code to build graph