close rpc client correctly. refactor worker into func so I can use defers