fix bug when adding multiple references to the last pointer in the list