Encoding and minor fixes