added further cleanup code to exit(int status) function