Move buildFlat to top level.