Fix reference insert NPE and build missing reference citations from pieces