changed logic to handle arbitrary layout definitions