fixed misc. bugs with switch to 'environment' flag.