(apart from replacing `x` with `x_flat`)