refactored setting env. and added some tests