Updated function GetD() (from Y. Belikov)