Add missing range() to loop