DRYing up some code