add exit logic when error