working on refining buffer algorithm (again!)