Fix incorrect handling of buffer.