rewriten env.rb to prevent future problem with Rack (stack too deep)