Refactor code. Fix problem with Selenium session