logic rewrite for layout