Refactor script pre-loading