Fix many UID and login bugs