Fix file cleanup.
Lock around reading the script file if we have to.
Fix some build configuration.
Fix some file leaks.
Some tuning… I hope.