Code cleanup and preparation for the Local chat