bug in for loop. Looped only once