if change_made:
                for i, item in enumerate(booklist):
                    if splc._needs_rewrite(item["ref"]):
                        print "* Rewriting ref {} ...".format(item["ref"])
                        item["ref"] = splc._rewrite(item["ref"])
                        print "...to {}".format(item["ref"])
                        next_list.append(item)
                        booklist[i] = None
                booklist = [n for n in booklist if n is not None]

        except IndexError:
            # once booklist is done, refresh counts, move next_list to booklist, start again
            if splc:
                refresh_count += 1
                if live:
                    splc.refresh_states()
                    Ref.clear_cache()
            needs_refresh = False
            booklist = next_list
            next_list = []
    if splc and needs_refresh:
        refresh_count += 1
        if live:
            splc.refresh_states()
            Ref.clear_cache()

print "Mishnah count: {}".format(m_count)
print "Gemara count: {}".format(g_count)
print "Refresh count: {}".format(refresh_count)

# Write out the new Mishnah Map
            if change_made:
                for i, item in enumerate(booklist):
                    if splc._needs_rewrite(item["ref"]):
                        print "* Rewriting ref {} ...".format(item["ref"])
                        item["ref"] = splc._rewrite(item["ref"])
                        print "...to {}".format(item["ref"])
                        next_list.append(item)
                        booklist[i] = None
                booklist = [n for n in booklist if n is not None]

        except IndexError:
            # once booklist is done, refresh counts, move next_list to booklist, start again
            if splc:
                refresh_count += 1
                if live:
                    splc.refresh_states()
                    Ref.clear_cache()
            needs_refresh = False
            booklist = next_list
            next_list = []
    if splc and needs_refresh:
        refresh_count += 1
        if live:
            splc.refresh_states()
            Ref.clear_cache()

print "Mishnah count: {}".format(m_count)
print "Gemara count: {}".format(g_count)
print "Refresh count: {}".format(refresh_count)

# Write out the new Mishnah Map