Added some clean-up code for module shutdown