Refactored JS script invocation