Improve buffer close