This pattern seems to be repeated a couple of times, it'd be nice if it were refactored in to a function.