working routing, but only for the first line segment. need to generalize my functions