Refactor code and DOM structure