Updated code to work with rpc