Optimized way of array output