move data reading/disconnecting to the client