Improve shutdown process