DRYed up the code by sticking it in a module.