Improved cleanup if file is in use.
Merge pull request #649 from schlamar/improved-cleanup

Improved cleanup if file is in use.