This is taken largely from EnvironmentUI.scala