[bug 1032226] Tweak the code to be more defensive