Set and cd to $TMP directory properly.
Add some documentation. Do cleanup.
Add logging.