js functions; basic chat alghoritm draft