optimized toArray