more refactoring and adding more env/config variables