Encode for 2.7

Handle encoding
Double check safety