Improved term tree building and added value calculation