Moved JS code to JS file