Fix some buffer bugs