This block is duplicated below, maybe extract a method