refactoring + basic test for agent remoting