In Act IV, we learn that Hamlet finds himself on a ship that is bound for England. However, the story eventually takes him back to Denmark. Hamlet is able to return thanks to the intervention of pirates, who attack the ship he is on and take him prisoner. This is a deus ex machina device, as it is unexpected and leads to the resolution of the story. Shakespeare shows how opposed the pirates and the royal family are by contrasting their intentions. The royal family want Hamlet killed, or at least exiled (particularly Claudius). On the other hand, the pirates recognize how valuable Hamlet is and want to protect him in order to claim a reward. The use of this device allows the drama to be heightened, as Hamlet is returned to Denmark. His return indicates that the climax of the story is coming soon, as well as its resolution.