refactor the makeBuffer function