Fix bug in context duplication during layout