adding adjacency-based numbering code