refactor, uses non-inline local buffer.