implementing graph search