DRYed up some of the code