Legion being carried off by swarms is because of who you chose for the assignments. you have to choose specific people for those assignments or you will lose someone.
If you have a save thats is right when you got legion, try to go back to it. Its like this, get legion back on your ship. Activate him and talk to him to unlock his loyalty mission. Then you can access the map to be able to run his mission before the ambush on your ship (my game allowed me to do it this way, but not everyone seemed to be able to do this. not sure why. Try and see how it plays out)
also, upgrade your ship before moving anywhere.
after you do legions mission, you can go back and open the map and it will now trigger the ambush on the ship. To avoid losing Kelly or any of the ship crew, u must go thru the omega 4 relay right away.
as for losing crew members, you just have to pick the right people to do stuff.
let Tali handle the vents. Have garrus, miranda or jacob be the fire leader
for the 2nd part, have Jack (dont use Samara cause she isnt loyal) protect you with the shield. Again have garrus, miranda or jacob handle the 2nd crew.
Also, have Mordin take the crew back to the ship
for the final fight, take tali and jack as your squad mates. Leave the others to defend the position.
If you do it like this, nobody will die
this link spells it all out for you. acroll down to act 3
http://masseffect.wikia.com/wiki/Mass_Effect_2_Guide