fix decode and encode