refactor code for webdriver