Modify identity selection logic / fix bugs