manually loop over long array instead of using .flatten