Added a missing null check to reference_piece