improved error handling

Change-Id: If01c1184a064de39da09f5a405968cfbd4e5f509