Now working version using environment