Refactored HTML and Javascript code