Problem dynamically generating an all purpose title tag

I wound up fixing it like this. All pages now work. But it looks …well …ugly.

<?php if (function_exists('is_tag') && is_tag()) {
    single_tag_title('Tag Archive for &quot;'); echo '&quot; | ';
} elseif (is_archive()) {
    wp_title(''); echo ' Archive | ';
} elseif (is_search()) {
    echo 'Search for &quot;'.esc_html($s).'&quot; | ';
} elseif (!(is_404()) && is_single() ) {
    wp_title(''); echo ' | ';
} elseif (is_404()) {
    echo 'Not Found | ';
} 
if ( is_front_page() ) {
    bloginfo('name'); echo ' | '; bloginfo('description');
} elseif ( is_page() || is_home() ) {
wp_title(''); echo ' | '; bloginfo('name');
} else {
    bloginfo('name');
}
if ($paged > 1) {
    echo ' | page '. $paged;
} ?>

error code: 521