implement terminateTask method