Reduces number of database queries made by triangularisation

Triangularisation references Person when in fact the inner loop does not depend on Person and instead refers solely to the SparseArray.

This commit modifies the triangularisation to only depend on the SpareArray.

(Just noticed that this actually iterates through the array in a slightly amusing manner, but the code should produce the same result)