Added log and corrected NPE.