Role of impurities and p-n junction formation in CdTe thin film solar cells