ajax refactoring, chat fixes