Refactored exceptions handling