Server shutdown refactored