refactoring handle tunnel loops