Fixed wrong loop iteration