Bug fixes for looping in graph.

Removal of formation of loops in the graph by restricting addition of edges.