Implement toMessage function