fixing a bug when converting terms to references (the global jTerm manager was not taken into account). And other minor refactorings