Fixed the shutdown procedure