Refactoring of html to js