Optimize buffer generate first and all edge cases