move some code to gracefully handle the case when a handler crashes.