move this function declaration outside of the for loop