Improved the exception handling