Refactoring router code to use routing table