finish most of nf. works correctly on all examples. need additional testing