Factor out logging and progress-bar code