refactored shutdown handler registration and added shutdown module hook