Refactor for exit code problem