Implement routing algorithm