Adding defensive programming to some fail cases