Fixed some bugs due to surprising behavior of structure in which same chain ids can appear in multiple distinct chains.