Resolved issues

Use .done() instead of .when().fail()
Move linkToPage declaration to be with the other variables