better logging and cleaner functional style when shutting down server