perf update: only iterate once over array.