DRYed out some of the code