bug fix and reviewed patchId-->indexNv
cleaned source code