Tidy up the exception handling