Refactor to remove big duplicated chunk of code.
Refactor to remove big duplicated chunk of code.

Checked for difference between the two blocks first - the only
difference was the apparent typo fixed in ca30f761ace.

SUNET/garethr-docker,SUNET/garethr-docker,SUNET/garethr-docker