refactory remoting related code.