Updated Encode and Decode to be url safe