Refactored for environment avriables