This is chat.py with threads with some other modifications