Player death function

Some cleanup here and some fixes. This resolves the issue pointed out in #2243.