Finished NFGraph constructor, now with sorting of elements