refactoring DOM logic to view