Do some basic error handling

Change-Id: I1f51791d904d674ff904bfc34312bb0c1d45d2b7