properly initialize output_buffer. removing unnecessary array conversion in encode function.