Fix a variety of issues related to the rebuild command, especially for routers in ERROR and BUILD.