Fixed wrong refactoring of perimeter tree traversal. #1832