refactor to make it a little easier for rpc