It might be nice to extract this entire `if` block into a private method now, because the indentation has got very deep and it will be slightly more readable.