Improve the logic for opening browser