optmized code in treaty.js