Fixed d2a functions (this version is faster, and in testing the previous version didn't work correctly)