Refactor script loading