Refactored link handler for code readability

* Split up a couple large, hard to comprehend conditions into
  their own helper methods. These functions could possibly be
  simplified further later on.

* No change in parser test results.

Change-Id: I1527ba33fb7d9fea2764cad27eb7110f5ab50656