moved script code to js file