Merge "Only clear preferred UID at appropriate times." into tm-dev