terminate function (coordinator)