fixed environment handling bug