loop arrays correctly