refactoring javascript as well as html