Error handling fixes.

Change-Id: If16d0d4b5e32eb2e945dadbe6fdc697abba9389a