Add code for graph visiting
As per the last commit