Updated message class with logging and error handling