I had this prob too. It would tilt open but not close, and the full opening packed in altogether.
A new relay fixed mine - about £35, but check which motor you have fitted as I believe there are different relays to suit.
I had a play on sunday, and managed to get the sunrrof working, however the automatic stop for fully closed stopped working, I put it all back together and it worked fine til today, may well try the relay route.
Yeah, mine rattles too, if you close the sun visor thing it stops. I found the plastic inside liners, (the bits you can see on each side of the sunroof) can pop loose and rattle in a very annoying fashion, a good squeeze back fixes it.