Moved some of the routing stuff into it's own file.

- Also a better check in the port driver for key iteration.
Fix error if we can't find the next key in the tree.