further tidy up of flattening transformation