adding the traversal either of outgoing or incoming refs
bug fix in the algorithm implementation
imporoved scenario