Fixing agent.js as in matt's branch