In later periods, Chinese writers referred to the demonic and celestial legal codes that the underworld judges had to apply. They apparently followed even more extensive rules than their earthly counterparts in courts staffed by an even more elaborate bureaucracy. In the underworld, they judged the deceased and entertained petitions from both unavenged ghosts and living petitioners.