re-factored js script creation