Fixed lib/encode: type conversion & reference err