Tweaked to avoid NPE.  issue#315