implement part of graph search