Trying to implement routing alg