fix bug layout was generated once instead of in thz loop