Fix possible NullPointerExceptions