Extend buffer and fix the trivial bug.