Fixed writing to output buffer