Refactored and added tests for David Waterston patch of routing