Consolidate all the id handling and caching code. am: b2922f64a8 am: cf19ed8c20
am: 19af773b9b

Change-Id: I3f9aaa8b4295d720f591b3916fe1b63afaafa0d1