Bugfixes, refactor, change death condition

Read the commit titles and descriptions for details.