Simple fixes

- Ensure temp files are cleaned up.
- Refactor a function with three return statements.