bugfixes and tweaks to Environment APIs