The name 'Hamlet' as used in the story is not purporting to refer to a fictional character, it is purporting to refer to a person; and only when we speak outside the story can we would also have the consequence that 'Moloch' was not the name of a pagan deity but came from a misvocalization of 'melech' ('king' in Hebrew).