Fix severe bug in NSD implementation.

Note that the bug only occurs for D >= 3 and
not for D = 1 or D = 2.