improved layout handling