Fix the if
Fix comment
Remove nested loop and move it