Move MAX_WRITE_SIZE to session. Explain session loop