refactor layout calculator