Maybe this section, which is now repeated, can be pulled into a method?