1006 Added extra guards against NPE