Use fast version for D

Apply fast version and move `dist` function to where it is used.
Merge pull request #52 from yazd/patch-1

Use fast version for D