modified NN code