This same code is duplicated further down. Can it be refactored into a method?