added proper reference deleting