Added logic to create a graph structure out of string