JS code moved from HTML to JavaScript file