need some help with some code

a friend of mine helped me about 3 years ago or so to change the educlean theme (the last of the 1.x version) so that it displays avatars next to the latest posts and latest comments on the front page.
Now since upgrading to wp 3.0.1 and having trouble with the original plugin generating the feeds I went in and changed quite a bit. So far I worked most of it out but I'd need someone to have a look and tell me if this can be done easier? Maybe he was adding overhead and I didn't know?

so basically these functions have been added or modified to functions.php and I can't seem to be able to wrap my head around all of if, so if you see obvious mistakes, I'd love to get this straight:

function author_avatar_xt() {
$the_author_email = get_the_author_email();
$the_author_name = get_the_author_nickname();
$pathtotheme = get_bloginfo('stylesheet_directory');
/*$md5 = md5($the_author_email);
$default = urlencode("$pathtotheme/images/mygif.gif");
echo "<img src='http://www.gravatar.com/avatar.php?gravatar_id=$md5&size=32&default=$default' alt='$the_author_name' />";*/
echo get_avatar($the_author_email);
}
//modified to be always small when on category page
function author_avatar_cat() {
$the_author_email = get_the_author_email();
$the_author_name = get_the_author_nickname();
$pathtotheme = get_bloginfo('stylesheet_directory');
/*$md5 = md5($the_author_email);
$default = urlencode("$pathtotheme/images/mygif.gif");
echo "<img src='http://www.gravatar.com/avatar.php?gravatar_id=$md5&size=32&default=$default' alt='$the_author_name' />";*/
echo get_avatar($the_author_email);
}

=> as far as I can see this has only been modified to call the gravatar differently, right? No harm done here?

then come these functions he added to help me get the avatar from the rss feeds:

function get_id_name($name){
global $wpdb;
$sql="Select id from wp_users where display_name='$name'";
return $wpdb->get_var($sql);
}
function get1_comment_author_email($name){
global $wpdb;
$sql="Select comment_author_email from wp_1_comments where comment_author='$name'";
return $wpdb->get_var($sql);
}

The first one seems to work, an example of our usage will follow below but the second one doesn't work as it is only looking into the comments of blog #1 and not in the right blog's comments table

Here is what we were doing with these functions (used inside rss-network.php) :

For the latest site-wide posts:

$feed_authorlink = $item['dc']['creator'];
$id=get_id_name($feed_authorlink);
$msg .= "
<div class=\"feed-pull\">
<span class=\"blog-avatar\">
".get_avatar($id,32)."
</span>

I have shortened that code, left only the necessary parts to show whats happening. Basically getting authorname from feed,figuring out his ID then showing the avatar.This works but always delivers the user uploaded avatar. Can't test right now if the gravatar would have precedence or not though? How to get this to show first gravatar if exists, then blog avatar, if not then user avatar? Guess its not doable as the blog avatar isn't related to the user?

For the latest site-wide comments:

$username = substr($item2['title'],0,strpos($item2['title']," "));
$id=get_id_name($username);

if (strlen($id)==0)
$id=get1_comment_author_email($username);
if (strlen($id)==0)
$id=$username;
$msg2 .= "
<div class=\"feed-pull\">
<span class=\"blog-avatar\">
".get_avatar($id,32)."
</span>

This is totally over my head. I don't know why the same function as for the latest articles isn't used for the latest comments too.

Sadly the guy helping me out a couple of years ago has long moved on, never again touched PHP and at that time was a fellow student who was tinkering with PHP a bit more than me so this might be very crude coding.
I know this is not related to any plugin of WPMUDEV I am just asking you guys who are code-happy to have a quick look as I know there are a lot of PHP savvy users around here, maybe I can fix this mess once and for all.