Fix null reference bug when unpublishing