final working NMF script