Fix some npes and Random errors.