implementing a local iterator2array to boost performance