fix some bugs reported by ACRA

Change-Id: I50c344d911f0153b8ea7aff70ca1f5b3c9b179bb