moving js code to js file