fix serious problem about reference count
fix problem of reference count and remove useless code