Fix bug causing temporary directories to not be deleted