Small optimizations and fixes

Change-Id: Ib691e030c6977ed6c391f05090427e2ff60eef65
Merge "Small optimizations and fixes"