add EXIT trap as set -e may terminate the program without a signal