refactor exit status calculation