Fixed compilation issues and buginess.

Change-Id: I6c0c370cdc84b60f0e344b76e13e0d18605fffb8