Improve previous refactoring (make exception handling more specific)