Encoding bugs fixed