Properly terminate the server