topology-driven version bfs

unfortunately, the code is a little buggy