Refactor code to return the layout matrix.