Improved error handling

Change-Id: I2e15672f182c3384896eba5a09e0d02e28afa99d