Refactor chat

[wip]