Refactor exception handling.