Moved javascript code to external js file