added returncode to terminate()