Add context manager for handling temp files, more unit tests.