added chat routing, removed some redundant and buggy code