fix buffer loop