Nil pointer fixes

Fixes: https://bugs.launchpad.net/bugs/1358585

Add missing error handling.