Extracted route-filtering logic and added a test