improve routing code