MaxV returns the atom label with the highest valency. A test to prevent a locally undefined coordinate system (Figure ) is still missing in algorithm 1. This test is performed afterwards by checking if there exists an atom i whose reference atoms are linearly aligned. If such an atom is found, its dihedral defining atom d is changed (preferably) to an atom from the same coordination sphere relative to i. Instead of testing afterwards, it is possible to include additional conditionals in algorithm 1 to reject a selection for d(i), if the reference of i is linear. This inline testing could be faster than the additional test afterwards, but it would further increase the amount of nested conditionals up to a point where the code becomes very hard to understand.