Added a more or less functional exception handler