Layout engine refactoring