added logs and trying to prevent NPE