encode and decode working