Safely closing the server