Fix a loop condition.
Improve function documentation.