Fixed a bug in assigning temp to new allocation. Clear other references