wrong order of looping