removes unused code, adds graceful exit.