conditional for destroy function