Simplified the problematic layout code.