Fixed bug: buffer termination