moved code to js file