Some refactoring of NNI.