Fixed AD bug when reading and writing users and groups with a retry pattern;cleaned up and corrected code redundancies