Added a configuration parameter to choose between Firefox and Headless modes along with minor refactoring