refactoring sync and async script loading