fix: use while instead of for