refactoring to use rpc