Clean up joints before destroying the body

Fixes #1913