refactored and add chat feature