rewrote env.rb to prevent prblem with stack level too deep