made count_nodes() recursive again