Added env parameter. Refactor