Simple fixes

- Ensure temp files are cleaned up.
- Refactor a function with three return statements.
Merge pull request #1 from edx/ned/tweaks-for-pr-3464

Simple fixes