backport the destroy method from the oldie gist
add @pzi suggestion
Updated minified version