With a little creativity here, this can be DRYed out