Shakespeare's Writing of Hamlet

Shakespeare spends a great deal of time extending the length of his play.   Hamlet spends a lot of time hesitating and overthinking what he needs to do, but sometimes acts very rashly.   He seems to really lust for revenge, to kill Claudius and avenge his father, yet he is distracted and irresolute (possibly because of his moral sense).   He can't seem to stay focused on the task at hand or to make up his mind.   Shakespeare could have been using this extra time to build up Hamlet's character or just to make the play longer and more enjoyable.
An example of Hamlet being indecisive is in the play's most memorable soliloquy: "To be, or not to be, that is the question: Whether 'tis Nobler in the mind to suffer..." is an entire speech based around Hamlet not being able to decide whether or not to kill himself.   He knows it would be easier just to kill himself, yet he doesn't.   He also thinks (or over-thinks) how fear of God forces people to deal with problems instead of escape them (commit suicide).  
Another exmple is when Hamlet walks in on Claudius.   He has the perfect opportunity to extract revenge and Claudius wouldn't even know what happened, but he doesn't.   Instead, he wastes time and loses his opportunity thinking about how Claudius could go straight to heaven (Hamlet wants him to go to hell) if he was slewn while praying.
A third example, this time of Hamlet acting rash, is when Hamlet hears Polonius behind the arras and stabs through it without a second thought.   This causes a chain reaction of killing in the last act, which eventually kills most of the main characters.   Shakespeare could've just as well had Hamlet kill Claudius at the end; instead he duels with Laertes, leaving a goblet of poisoned wine which Gertrude drinks, slicing Laertes with his own poisoned sword after himself being sliced then stabbing Claudius to death.  
Hamlet gets distracted quite a bit from killing Claudius along the way.   The play where the his father was murdered in Act 2...