cleaned up tmpclient, improved error handling