Update function to encode and decode message