Move logic from HTML to JS.