moved code to a js file