replaced buffer code with array version