Fixed some problems uncovered via code inspection.

Change-Id: Ibaf165dcbe62f0096805f1d2cda5bf36882ffce7