Use defensive programming to fix the crash-bug mess