Fix the descendants method

One shall be careful when modifying an array which is being iterated. Even though the iteration always finishes in this particular case, it may generate many duplicate nodes in the result. The fix prevents this.