fix decode function