Refactor code and add comments.
(More) Reliably determine when the scan is done.

For that, we keep track of how many circuits were built or failed and how many
streams are finished.
Show scan duration in statistics.