Add comment explaining algorithm