Clean up temporary directories.

Initially a bit of a hack, but works.
Put temporary files in temporary directories.