Bugfixes and error handling for commit dcbfae0f15689b2e48cc811af6db04ce5a3ca10f

Change-Id: Ic5901b2876de1bd58ddcd29aeaf393bdfa38f76e