fixed bug around deleting references