DRYed up the code

I just used the code as a typing kata and realised I had to type some code twice.

So here is a patch to DRY it up.