The code here is almost entirely duplicated from the block above.