DRY up this code