Improve logging and error handling in server