Implemented proper shutdown.