Switched from while() to for()