Router code and tests