Added guard against a potential nullpointer exception which I can't reproduce.