Add null protection for client/server sides of handleChat