Graph search code