Simplifying arrrays to strings and eliminate loops