Some code re-arranging and cleanup for speedup

The construction of the list of links is now done in a cleaner way, and instead of cycling over all possible pairs of papers, only the upper triangle of the links matrix is considered (because this is a symmetrical relationship, and the diagonal is irrelevant).