This is really odd to follow. The result is that everything continues, so why not just extend the visited_nodes in the specific branches, and move the continue to after the if statements so that it's clear that everything hits the continue?