Refactoring traversal algorithms to use boundaries