Add error checking. Update unit tests to fully cleanup temporary files.