abstracted embedded javascript code from script tag to seperate js file