Fixed some problems when shutting down and restarting the module