Refactor loadAndInlineScript()
Clean up