finalized refactoring of HTML and JS