refactor read_env method internally