Add comment to explain algorithm