The construction and function of late medieval cathedrals