Major optimizations

Change-Id: Ic52a356cb0fd33525c5779b18993aa49a7da752b