improved the 'destroy' function