Rearrange environments and tidy up some function names