move this up, outside the inner for loop