fixed destroy function