Abstract graph search related code into a module.