DRYed it up somewhat