Added a null check for OnChat