Refactoring the strongly_connected_components function.