Fixed routing functions. Previous code worked but was inflexible.