various fixes and write ntriples rewrite