adding encode and decode