renaming directories with shell script

Hi All
after looking around the website and various other resources I become stuck. I'm trying to rename directories from

Firstname Initial Lastname to lastname,_firstname_initial

so far ive got

for f in {./}
do

rename -n 'y/A-Z/a-z/' *
rename -n 's/\ /_/g' *
done

This is working well at removing the capital letters and deleting the spaces in the directory names, I just can't work out how to reverse the order of the names.

I was looking at

name=${f}
last=${name%\w+}

not to sure how to get the rest of it together.

thanks for any assistance

This should work (replace the mv by echo for testing!)
for F in ; do
F2=${F#
}
mv "$F" ${F##* },${F%% *}${F2% *}
done

Thanks for that your code worked great.