Fix build warnings and code simplify

Change-Id: Iee02fbde6b9f6cac60f0bc91a8b9bf915ddd5032