Improved LogFact function. Now it is far faster. The addnode and rmnode can also be improved...