fixed broked for loop