moving last_ref_id out