modularlize chat logic