Tidied up exception handling.