Get rid of match statements in Layout queries.(fixes #2019)

see #2019