added logic to handle terminate actions more flexibly

added logic to handle terminate actions more flexibly