Exception handling refactoring