fixed bugs that prevented shutdown