i would do the initialisation outside this function anyway; but this needs to be done outside this foreach loop