fixed the looping over xi