improve destroy function