Added message writing functionality