modified code and added pgd for dd