Made some changes and before unload event for invoking exit call.