Add some extra error checks

Change-Id: I78184dd9a99d9a399357420c247721cb5b4019f1