Further testing showed issues with temp file changes, hopefully this fix seems to work and should fix any further issues with file locking, need to test on windows.