Handle fatal errors

Taking over #843