clean unreference function