cleanup references logic