improved digraph construction algorithm