Optimize by removing dependency on to-array