Optimize array functions