Mirror the encoding behavior more closely in decode function