refactoring and added test environ logging