For #236 cleanup routing code and add tracing.