Corrected For loop early termination