updated client with flushing and closing of socket etc.