[BUGFIX] Added null check to prevent NPE