get an A in CodeClimate by DRYing code

Not sure it's easier to read though!