encounter.js code cleaning