add dom parsing and refactor code