Copying functionality from ImprovedChat mod

Not ready, but getting there.