Added error handling to server and server shut down