Added better environment detecting facilities