new function to generate ndx