This block is pretty identical in this method. Could it be refactored in a dedicated method to be easier to read?