I found the following thread useful. I'm going to try it out:

when your main dies