Perf improvement

reduce amount of array copies