We analyze a repeated prisoners' dilemma game played in a community setting with heterogeneous types. The setting is such that individuals choose whether to continue interacting with their present partner, or separate and seek a new partner. Players' types are not directly observed, but may be imperfectly inferred from observed behavior. We focus on a class of equilibria that satisfy zero tolerance and fresh start. We find that the punishment for defecting and the reward for cooperating are driven by the formation and the dissolution of long-term, high-paying relationships: an individual who defects, aborts a long-term relationship that he is in, or that he might have entered into, is thrown into short-term interactions with individuals who are likely to defect and, consequently, receives low payoffs. On the flip side, an individual who cooperates, enters into or prolongs a long-term interaction with a partner who cooperates and, consequently, receives high payoffs.