D2k cleanup

This is pull request #2457 rebased onto latest bleed with lot's of changes because of pull request #2476. It took several days and it is now RALint clean.