enhanced the destroy function