speed improvements in ndqf.py