Refactoring the script parsing method