moved js code to js file