Refactored the script file handling.