decode function modified