Geez that's scary. I'm one of those people that's paranoid about fires. If I make dinner then go to bed, I'll get up two or three times to check and make sure that the stove and oven are off! It's a little bit OCD... I was always paranoid when I had my tank. Saltwater and electricity don't mix.
I'm really glad you woke up and were able to yank that heater out before a fire started.
I'm no electrician, so I don't know if it would have helped or not, but do you have your equipment plugged into a GFCI outlet? I had a handy friend come over and install a GFCI outlet where I plugged all my tank stuff in when I set it up.