write function updated for longer messages.