Tidy up the way build environments are set (via State rather than via cloning and changing the tree). Also a bit of other tidying.