add encode and decode function