close logic and almost working rpc