refactor to chat iteration