made the decode function completely reversible