Bug fixes with buffer handling