Nanopatterning and bandgap grading to reduce defects in CdTe solar cells