iterative version of BFS call chain generation