clean function removes the last reference and everything is ok