Refactor some repeated code.
Refactor some repeated code.

ocadotechnology/calico,alexhersh/calico,matthewdupre/felix,neiljerram/felix,anortef/calico,kasisnu/calico,kasisnu/calico,neiljerram/felix,neiljerram/felix,neiljerram/felix,anortef/calico,matthewdupre/felix,beddari/calico,TrimBiggs/calico,Metaswitch/calico,Metaswitch/calico,ocadotechnology/calico,TrimBiggs/calico,beddari/calico,alexhersh/calico