Refactored shutdown procedure and logging