Refactoring Depth First Search for better readability